<template>
	<view class="container">
		<view class="timeInfo">
			<text class="timeInfo-Text">以下是等待接单的老雇员</text>
			<view class="timeInfo-Buton">
				<view :class="[isSelectButton ? 'select-Button':'selected-Button']"
					@click="isSelectButton=false,flagTime=0">今天任务</view>
				<view :class="[isSelectButton ? 'selected-Button':'select-Button']"
					@click="isSelectButton=true,flagTime=1" style="transform: rotateY(180deg);"><text
						style="transform: rotateY(180deg);">明天任务</text></view>
			</view>
		</view>
		<view class="list">

			<view class="employee-infos" v-for="item in staffList" :key="item.userId"
				:style="{'background-color':jf_staffList.includes(item.userId) ? '#efefef' : ''}"
				v-if=" item.num==0  && !userIds.includes(item.userId)&&(item.usex==item.tsex||item.tsex==2)&&item.ordernum==0">

				<view class="infoLisy">
					<view class="staff-infos-items-vip-crown" :class="{'vip-avatar':item.vip_flag==1}">
						<image :class="item.vip_flag==0?'avatar-pic':'avatar-pic-vip'" :src="imgPath + item.avatar" mode="aspectFill"
							@click="handleOpenDetail(item.userId)"></image>
						<view v-if="item.vip_flag" class="vip-crown">
							<image src="http://images.linglinggong.net/icon3/adasdasd.png" mode="aspectFill"></image>
							<text>金牌</text>
						</view>
					</view>
					<view class="nameList" @click="handleOpenDetail(item.userId)">
						<view class="nameList-list">
							<text class="names">{{ item.username }}</text>
							<view v-if="item.usex==0" class="sex-nan"><image class="sex-image" src="http://images.linglinggong.net/icon3/nna1111.png" mode="aspectFill"></image>{{!item.age ? '未知' : item.age}}</view>
							<view v-if="item.usex==1" class="sex-nv"><image class="sex-image" src="http://images.linglinggong.net/icon3/nv111.png" mode="aspectFill"></image>{{!item.age ? '未知' : item.age}}</view>
						</view>
						<view class="cxDiv">
							<view class="cx">
								<text>评分</text>
								<text
									:style="{color:jf_staffList.includes(item.userId) ? '#7F7F7F' : ''}">{{ item.integrity/100 }}</text>
							</view>
							<text class="fg">|</text>
							<view class="cx">
								<text>好评率</text>
								<text
									:style="{color:jf_staffList.includes(item.userId) ? '#7F7F7F' : ''}">{{ item.haoping }}%</text>
							</view>
						</view>
					</view>

					<view :class="isSelect.includes(item.userId)&&!jf_staffList.includes(item.userId) ? 'selected' : 'select'"
						@click="jf_staffList.includes(item.userId)?'':selctFun(item.userId)">

					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="hasFlag ? 'loading' : 'noMore'"></uni-load-more>
		<view class="fabu" @click="fabuButton">{{isSelect.length==0?'(不邀请)快速发布':'(已选'+isSelect.length+'人)邀请发布'}}</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import {
		get_praise_or_goodFaith,
		he_evaluate_lv,
		get_user_status
	} from '../../libs/unit.js'
	export default {
		data() {
			return {
				hasFlag: false, //是否加载完成
				imgPath: '', //图片路径
				requestObj: {
					newdate: 0, //0是今天1是明天以此类推 
					pageNum: 0,
					pageSize: 10,
					taskId: 0,
				},
				staffList: [], //雇员列表
				jf_staffList: [], //被禁封的id
				isSelect: [], //选中的item
				taskId: 0, //任务id
				workObj: { //他的工作
					pageNum: 1,
					pageSize: 10,
					userId: '',
					orderByColumn: 'create_time',
					isAsc: 'asc',
				},
				isSelectButton: false, //时间切换按钮
				userIds: [], //已被邀请的id
				flagTime: 0, //今天和明天的flag今天0 明天1 。。
				pageType: -1, //功能监测---一键发布1任务中心发布/2历史发布
				praise_or_goodFaith: 0, //	0是显示好评度1是显示诚信值9是两个都显示
				handleIsStop: true, // 是否允许切换
			}
		},
		watch: {
			isSelectButton() {
				uni.startPullDownRefresh({
					fail() {
						uni.showToast({
							title: '刷新失败，请下拉重新刷新',
							icon: 'none'
						})
					}
				})
				this.isSelect = []
			},
		},
		methods: {
			// 刷新
			refresh() {
				this.staffList = []
				this.hasFlag = true
				this.requestObj.pageNum = 0
				this.requestObj.pageSize = 10
				this.my_hire()
				//this.order_list_by_taskId()
			},
			//多选按钮点击事件
			selctFun(id) {
				if (this.isSelect.length >= 99) {
					uni.showToast({
						title: '已超过最大可邀请人数了哟',
						icon: 'none'
					})
					return
				}
				let index = this.isSelect.indexOf(id)
				if (index == -1) {
					// this.$set(this.isSelect, this.isSelect.length, id)
					get_user_status(id).then((v) => {
						if (v.code == 500) {
							uni.showToast({
								title: v.msg,
								icon: 'none'
							})
							this.jf_staffList.push(id)
						}else{
							this.$set(this.isSelect, this.isSelect.length, id)
						}
						//console.log(v,this.jf_staffList)
					})
				} else {
					this.isSelect.splice(index, 1)
				}
			},
			// 打开雇员详情
			handleOpenDetail(staffId) {
				uni.navigateTo({
					url: '/pages/employer-detail/employee-detail?staffId=' + staffId + '&isOldPage=' + 'true'
				})
			},
			//判断雇员是否背负任务 
			async he_task(userid) {
				this.workObj.userId = userid
				let res = await this.$fetch(this.$api.he_task, this.workObj, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				if (this.flagTime == 1) {
					if (this.isTaskToday(res.data.acceptTask.rows[0].taskStartTime) != 1) {
						return true
					} else {
						if (res.data.acceptTask.rows[0].status == 0 || res.data.acceptTask.rows[0].status == 5 || res
							.data
							.acceptTask.rows[0].status == 9) {
							return true
						} else {
							return false
						}
					}
				} else if (this.flagTime == 0) {
					if (this.isTaskToday(res.data.acceptTask.rows[0].taskStartTime) != 0) {
						return true
					} else {
						if (res.data.acceptTask.rows[0].status == 0 || res.data.acceptTask.rows[0].status == 5 || res
							.data
							.acceptTask.rows[0].status == 9) {
							return true
						} else {
							return false
						}
					}
				}
			},
			//判断是否为今天0 明天1 还是其他天3
			isTaskToday(time) {
				time = time.split(' ')[0]
				let date = new Date(time.replace(/-/g, '/')).getTime() / 1000;
				let d = new Date(new Date(new Date().getTime()).setHours(8, 0, 0, 0)).getTime() / 1000;
				if (date == d) {
					return 0
				} else if (date - d == 86400) {
					return 1
				} else {
					return 2
				}
			},
			// 获取我的雇员
			async my_hire() {
				let haoping = uni.getStorageSync('heEvaluateLv') ? uni.getStorageSync('heEvaluateLv') : []
				if (!this.hasFlag) return // 说明已经没有更多啦
					++this.requestObj.pageNum
				if (!this.handleIsStop) return uni.showToast({
					title: '你点击得太快啦~',
					icon: 'none'
				}) // 说明上一条请求结果未返回
				this.handleIsStop = false
				this.requestObj.taskId = this.taskId
				this.requestObj.newdate = this.flagTime
				let res = await this.$fetch(this.$api.my_order_employer, this.requestObj, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				await res.rows.forEach((e) => {
					// this.he_task(e.userId).then((v) => {
					// 	this.$set(e, 'isShow', v)
					// })
					if (haoping.indexOf(e.userId) != -1) {
						e.haoping = haoping[haoping.indexOf(e.userId) + 1]
						//this.$set(e, 'haoping', haoping[haoping.indexOf(e.userId)+1])
					} else {
						he_evaluate_lv(e.userId).then((v) => {
							this.$set(e, 'haoping', v)
						})
					}
				})
				uni.stopPullDownRefresh()
				this.handleIsStop = true
				this.staffList = [...this.staffList, ...res.rows]
				this.hasFlag = this.requestObj.pageSize * this.requestObj.pageNum < res.total
			},
			//他的好评率
			// async he_evaluate_lv(id) {
			// 	let parameters = {
			// 		"type": 0,
			// 		"userId": id
			// 	}
			// 	let res = await this.$fetch(this.$api.he_evaluate_lv, parameters, 'POST')
			// 	if (res.code) return uni.showToast({
			// 		title: res.msg,
			// 		icon: 'none'
			// 	})
			// 	let f = parseFloat(res.data)
			// 	f = Math.round(f * 100)
			// 	return f
			// },
			fabuButton() {
				uni.navigateTo({
					url: '/pages/quickSendJob/quickSendJob?taskId=' + this.taskId + '&timeFlag=' + this.flagTime +
						'&people=' + 1 + '&page=' + this.pageType
				})
				if (this.isSelect.length != 0) {
					setTimeout(() => {
						let pages = getCurrentPages()
						//console.log(pages[pages.length - 1])
						pages[pages.length - 2].$vm.getStaff(this.isSelect)
					}, 1000)
				}
			},
		},
		onLoad(options) {
			console.log(options)
			this.taskId = options.taskId
			this.pageType = options.page
			this.imgPath = uni.getStorageSync('imgPath')
			this.refresh()
			get_praise_or_goodFaith().then((v) => {
				this.praise_or_goodFaith = v
			})
		},
		onShow() {
			// uni.$once('selctFun', (v) => {
			// 	this.selctFun(parseInt(v))
			// })
		},
		onReachBottom() {
			this.my_hire()
		},
		onPullDownRefresh() {
			//监听用户下拉动作，一般用于下拉刷新
			this.refresh()
		},
	}
</script>

<style lang="less" scoped>
	.container {
		overflow: hidden;
		display: flex;
		align-items: center;
		flex-direction: column;

		&>.list {
			background-color: #FFFFFF;
		}
	}

	.employee-infos {
		width: 750rpx;
		height: 186rpx;
		background: #FBFBFB;
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 2rpx solid #F5F5F5;
	}

	.infoLisy {
		display: flex;
		height: 108rpx;
		width: 690rpx;
		align-items: center;
		justify-content: space-between;
	}

	.avatar-pic {
		width: 108rpx;
		height: 108rpx;
		border-radius: 50%;
	}

	.nameList {
		margin-left: 30rpx;
		width: 108rpx;
		height: 108rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.names {
		font-size: 34rpx;
		font-weight: 500;
		color: #3E220A;
		line-height: 45rpx;
	}

	.xb {
		width: 26rpx;
		height: 26rpx;
		margin-left: 17rpx;
	}

	.cx {
		font-size: 24rpx;
		font-weight: 400;
		color: #7F7F7F;
		line-height: 49rpx;

		&>text:nth-last-child(1) {
			color: #FE4B28;
			margin-left: 8rpx;
		}
	}


	.select {
		width: 42rpx;
		height: 42rpx;
		border: 2rpx solid #402110;
		opacity: 0.3;
		border-radius: 50%;
		text-align: center;
	}

	.selected {
		width: 44rpx;
		height: 44rpx;
		background-image: url(http://images.linglinggong.net/icon1/hdg.png);
		background-repeat: repeat;
		background-size: 100% 100%;
	}

	.alert {
		background-color: #F8D979;
		width: 750rpx;
		height: 80rpx;
		background: #F8D979;
		text-align: center;

		&>text {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #3E220A;
			line-height: 45rpx;
			position: relative;
			top: 20%;
		}
	}

	.yq {
		width: 750rpx;
		height: 98rpx;
		display: flex;
		position: fixed;
		bottom: 0;

		&>view:nth-child(1) {
			width: 509rpx;
			height: 98rpx;
			background-color: #FFFFFF;
			font-size: 28rpx;
			font-weight: 500;
			color: #402110;
			line-height: 45rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		&>view:nth-child(2) {
			width: 240rpx;
			height: 98rpx;
			background-color: #FCC928;
			font-size: 28rpx;
			font-weight: 500;
			color: #402110;
			line-height: 45rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.timeInfo {
		display: flex;
		align-items: center;
		height: 124rpx;
		width: 690rpx;
	}

	.timeInfo-Text {
		font-size: 28rpx;
		font-weight: 500;
		color: #402110;
		line-height: 45rpx;
	}

	.timeInfo-Buton {
		width: 304rpx;
		height: 68rpx;
		margin-left: 30rpx;
		display: flex;
	}

	.se-button {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #402110;
		width: 152rpx;
		height: 68rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 12rpx 0 0 12rpx;
		background-color: #FFF;
	}

	.selected-Button {
		.se-button;
		background: #FCC928;
	}

	.select-Button {
		.se-button;
	}

	.fabu {
		width: 750rpx;
		height: 98rpx;
		background: #FCC928;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #402110;
		line-height: 45rpx;
	}
	.cxDiv {
		display: flex;
		flex-direction: row;
	}
	.fg {
		font-size: 24rpx;
		color: #7F7F7F;
		line-height: 49rpx;
		margin: 0 20rpx;
	}
	.sex-nan {
		width: 73rpx;
		height: 32rpx;
		background: #1CAAEA;
		border-radius: 4rpx;
		margin-left: 8rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		font-size: 20rpx;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 20rpx;
	}
	.sex-nv {
		width: 73rpx;
		height: 32rpx;
		background: #F90865;
		border-radius: 4rpx;
		margin-left: 8rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		font-size: 20rpx;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 20rpx;
	}
	.sex-image {
		width: 17rpx;
		height: 17rpx;
		margin-right: 9rpx;
	}
	.nameList-list {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.staff-infos-items-vip-crown {
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 108rpx;
		height: 108rpx;
	}

	.vip-crown {
		// width: 148rpx;
		padding: 0 10rpx;
		height: 32rpx;
		background: linear-gradient(0deg, #111832, #343B54);
		border-radius: 16rpx;
		position: absolute;
		top: 78rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;

		&>image {
			width: 28rpx;
			height: 28rpx;
			margin-right: 4rpx;
		}

		&>text {
			font-size: 20rpx;
			font-weight: 500;
			color: #FCC928;
			line-height: 32rpx;
		}
	}
	.avatar-pic-vip {
		width: 105rpx;
		height: 105rpx;
		border-radius: 50%;
		border: 3rpx solid #FCC928;
	}
	
	.vip-avatar {
		width: 130rpx;
		height: 130rpx;
		background-image: url(http://images.linglinggong.net/icon3/7868789.png);
		background-size: cover;
	}
</style>
